package com.gengzp.system.controller;

import com.gengzp.common.model.generic.resp.Result;
import com.gengzp.common.model.user.req.LoginSysUserReq;
import com.gengzp.common.model.user.req.RegisterSysUserReq;
import com.gengzp.common.model.user.resp.LoginSysUserResp;
import com.gengzp.permission.annotation.AuthIgnore;
import com.gengzp.system.service.SysUserAuthorizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SysUserAuthorizationController
 * @Description 系统用户授权模块控制层
 * @Author gengzp
 * @Date 2025/9/8 15:22
 */
@RestController
@RequestMapping("/user/authorization")
@Api(tags = "系统用户授权模块")
public class SysUserAuthorizationController {

    @Autowired
    private SysUserAuthorizationService sysUserAuthorizationService;

    /**
     * 用户注册
     */
    @AuthIgnore
    @PostMapping("/register")
    @ApiOperation(value = "用户注册")
    public Result<LoginSysUserResp> register(@Valid @RequestBody RegisterSysUserReq req) {
        return Result.getSuccessResult(sysUserAuthorizationService.register(req));
    }

    /**
     * 用户登录
     */
    @AuthIgnore
    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public Result<LoginSysUserResp> login(@Valid @RequestBody LoginSysUserReq req) {
        return Result.getSuccessResult(sysUserAuthorizationService.login(req));
    }

    /**
     * 用户退出登录
     */
    @PostMapping("/quit")
    @ApiOperation(value = "用户退出登录")
    public Result<Void> quit() {
        sysUserAuthorizationService.quit();
        return Result.getSuccessResult();
    }

}
